#include <stdio.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <unistd.h>

int main() {
    int fd = open("C:\\workspace\\c_study\\test.txt", O_RDWR);
    off_t length = lseek(fd, 0, SEEK_END);
    printf("%d\n", length);

    char * start = (char *)mmap(NULL,40,PROT_READ|PROT_WRITE, MAP_PRIVATE, fd,-10);

    // 读文件
    char *buf;
    memcpy(buf, start, 100);

    printf("%s", buf);


    // 写文件
    char *content = "Write to file**";
    memcpy(start, content, strlen(content));

    close(fd);
    munmap(start, 128);

    return 0;
}
